package com.oocl.server.http;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class HttpResponse {
	private Socket socket;

	public HttpResponse(Socket socket) {
		super();
		this.socket = socket;
	}
	
	public void write(InputStream inputStream){
		try {
			OutputStream out =  socket.getOutputStream();
			byte[] buf = new byte[inputStream.available()];
			inputStream.read(buf);
			out.write("HTTP/1.1 200 OK\r\n".getBytes());
			out.write("\r\n".getBytes());			
			out.write(buf);
			out.close();
			inputStream.close();
			socket.close();			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void write(String content){
		try {
			BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
			out.write("HTTP/1.1 200 OK\r\n");
			out.write("\r\n");
			out.write(content);
			out.close();
			socket.close();			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
